package com.kingyea.app.market.publishMarket.controller;

import com.kingyea.app.market.publishMarket.bean.PublishMarket;
import com.kingyea.app.market.publishMarket.service.PublishMarketService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author
 * @version v1.0.0
 * @description PublishMarket 控制层
 * @date Created in 2018-03-19 15:48:00
 */
@RequestMapping(value = "/publishMarket")
@RestController
public class PublishMarketController {

    private static final Logger LOGGER = LoggerFactory.getLogger(PublishMarketController.class);

    @Autowired
    private PublishMarketService publishMarketService;

    /**
     * 查询全部
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Object list(@RequestBody Map<String, Object> obj) throws Exception {
        return publishMarketService.list(obj);
    }

    /**
     * @param obj 查询   不分页
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getAll", method = RequestMethod.POST)
    public Object getAllPublishMarket(@RequestBody Map<String, Object> obj) throws Exception {
        return publishMarketService.getAllPublishMarket(obj);
    }

    /**
     * 通过ID查找对象
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.POST)
    public PublishMarket detail(@PathVariable String id) throws Exception {
        return publishMarketService.getById(id);
    }

    /**
     * 创建
     *
     * @param publishMarket
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public Object create(@RequestBody PublishMarket publishMarket) throws Exception {

        return publishMarketService.save(publishMarket);
    }

    /**
     * 创建
     *
     * @param publishMarketList
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/creates", method = RequestMethod.POST)
    public Object creates(@RequestBody List<PublishMarket> publishMarketList) throws Exception {
        return publishMarketService.saveList(publishMarketList);
    }

    /**
     * 更新
     *
     * @param publishMarket
     * @return
     */
    @RequestMapping(method = RequestMethod.PUT)
    public PublishMarket update(@RequestBody PublishMarket publishMarket) throws Exception {
        publishMarketService.update(publishMarket);
        return publishMarket;
    }

    /**
     * 删除
     *
     * @param publishMarket
     * @return
     */
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    public Object delete(@RequestBody Map<String, Object> publishMarket) throws Exception {
        String id = publishMarket.get("id").toString();
        return publishMarketService.deleteById(id);
    }

    /**
     * 发布市场列表
     *
     * @param obj
     * @return
     */
    @RequestMapping(value = "/marketList", method = RequestMethod.POST)
    public Object markList(@RequestBody Map<String, Object> obj) throws Exception {
        return publishMarketService.marketList(obj);

    }

}
